package com.tj.bo.common.conf.config.service;

import com.fqgj.base.services.redis.RedisClient;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * Created with IntelliJ IDEA.
 * User: binary
 * Date: 2020/4/29
 * Time: 下午2:16
 */
@Component
public class ApplicationConfig {

    private static final Logger LOGGER = LoggerFactory.getLogger(ApplicationConfig.class);

    @Autowired
    private RedisClient redisClient;

    public String getProperty(String namespace, String key, String defaultValue) {
        String value = redisClient.hGet(namespace, key);
        return value == null ? defaultValue : value;
    }

    public Integer getIntProperty(String namespace, String key, Integer defaultValue) {
        try {
            String value = redisClient.hGet(namespace, key);
            return value == null ? defaultValue : Integer.valueOf(value);
        } catch (Exception ex) {
            LOGGER.warn("Conversion failed", ex);
            return defaultValue;
        }
    }

    public Boolean getBooleanProperty(String namespace, String key, Boolean defaultValue) {
        try {
            String value = redisClient.hGet(namespace, key);
            return value == null ? defaultValue : Boolean.valueOf(value);
        } catch (Exception ex) {
            LOGGER.warn("Conversion failed", ex);
            return defaultValue;
        }
    }
}
